package com.wchen.gdoc;

import com.wchen.gdoc.generate.DocumentGenerateManager;
import com.wchen.gdoc.generate.config.ApplicationConfig;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 涉及其他模块自行添加模块依赖
 * 
 * @author  wchen
 * @date    2019/11/11
 */
public class AppMain {


    public static void main(String[] args) {
        ApplicationConfig applicationConfig = ApplicationConfig.instance();
        StringBuilder classPaths = new StringBuilder();
        String projectName = "TEST";
        String moduleName = "demo";

        String preUrl = "http://localhost:5000/app";
        String contentTemplatePath = "content.ftl";
        //要扫描的项目
        String targetProjectPath = "demo";
        String[] classPathDs = {"UserController"};
        //要扫描的文件
        String packagePath = "com.wchen.demo.controller.%s.java;";
        for (String classPathD : classPathDs) {
            classPaths.append(String.format(packagePath, classPathD));
        }

        //相关值设置
        applicationConfig.getTargetProjectConfig().setExclusiveFieldMap(createCustomClass());
        applicationConfig.getTargetProjectConfig().setTargetScanPath(classPaths.toString());
        applicationConfig.getTargetProjectConfig().setTargetProjectPath(targetProjectPath);
        applicationConfig.getDocumentConfig().setContentTemplatePath(contentTemplatePath);
        applicationConfig.getDocumentConfig().setPreUrl(preUrl);
        applicationConfig.getDocumentConfig().setProjectName(projectName);
        applicationConfig.getDocumentConfig().setModuleName(moduleName);
        DocumentGenerateManager analysisManager = new DocumentGenerateManager();
        analysisManager.start();
    }


    private static Map<String, List<String>> createCustomClass() {
        Map<String, List<String>> customMap = new HashMap<>();

        List<String> fieldList = new ArrayList<>();
        fieldList.add("total");
//        fieldList.add("size");
        fieldList.add("hitCount");
        fieldList.add("isSearchCount");
        fieldList.add("optimizeCountSql");
        fieldList.add("orders");
        customMap.put("com.baomidou.mybatisplus.extension.plugins.pagination.Page", fieldList);

        List<String> fieldList2 = new ArrayList<>();
        fieldList2.add("queryClazz");
        customMap.put("com.mop.app.common.PageQueryWrapper", fieldList2);

        return customMap;
    }
}
